﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Core
{
    public static partial class msg
    {
        public static dynamic sendMsg(string username, string to, string title, string content)
        {
            var sql = new Sql.SqlDataContext();
            var u2 = sql.User.FirstOrDefault(row => row.username.ToLower() == to.ToLower());
            if (u2 == null) return new
                {
                    success = false,
                    msg = "接收方不存在"
                };
            else if (u2.disabled) return new
             {
                 success = false,
                 msg = "接收方已停用"
             };
            var m = new Sql.Message
            {
                title = title,
                from = username,
                to = u2.username,
                time = DateTime.Now,
                content = content,
                read = false
            };
            sql.Message.InsertOnSubmit(m);
            sql.SubmitChanges();
            return new
            {
                success = true
            };
        }
    }
}